package com.jse.io.nio.channel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

import org.junit.Test;

public class FileChannelTest {
	
	@Test
	public void testTransfer() {
		FileInputStream input = null;
		FileOutputStream output = null;
		
		try {
			input = new FileInputStream(new File("src/main/java/com/jse/io/nio/channel/input.txt"));
			output = new FileOutputStream(new File("src/main/java/com/jse/io/nio/channel/output.txt"));
			FileChannel inputChannel = input.getChannel();
			FileChannel outputChannel = output.getChannel();
			
			long remainingSize = inputChannel.size();
			long originalSize = remainingSize;
			inputChannel.transferTo(originalSize - remainingSize, 9*1024, outputChannel);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				input.close();
				output.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
}
